package com.example.rabbitmq_producer.msg.controller;

import com.example.rabbitmq_common.vo.UserVo;
import com.example.rabbitmq_producer.msg.service.RabbitMQService;
import com.example.rabbitmq_producer.util.ChineseNameUtil;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

/**
 * @ClassName RabbitMQController
 * @Description TODO
 * @Author gql
 * @Date 2023/3/10 18:05
 **/
@RestController
@RequestMapping("/mall/rabbitmq")
public class RabbitMQController {


    @Resource
    RabbitMQService rabbitMQService;

    @RequestMapping("/sendMsg")
    public String sendMsg(){
        return rabbitMQService.sendMsg("发送了一条消息");
    }

    @RequestMapping("/sendBody")
    public String sendBody(){
        UserVo vo = new UserVo();
        vo.setId(UUID.randomUUID().toString());
        vo.setName(ChineseNameUtil.getChineseName());
        List<Integer> list = Arrays.asList(10, 11, 12, 14, 15, 16, 20, 25, 26);
        vo.setAge(list.get((int)(Math.random() * list.size())).toString());
        return rabbitMQService.sendBody(vo);
    }
}
